// 自动锁定高亮菜单栏
function checkSelectMenu(name) {
    if (document.referrer === "") {
        alert("禁止直接通过地址栏跳转!");

        window.location.href = 'backend/dashboard';
    }

    $(".selectMenu").each(function (i, item) {
        if ($(this).prop('id') !== name) {
            $(this).removeClass("active");
        } else {
            $(this).addClass("active");
        }
    });
}

function getUrlParam(name) {
    let reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
    let r = window.location.search.substr(1).match(reg);
    if (r != null) return unescape(r[2]);
    return null;
}

function formatTime(str) {
    return Date.parse(new Date(str));
}

//创建时间格式化显示
function crtTimeFtt(value) {
    if (null == value || value === '' || value === undefined) {
        return "";
    }
    /*value = parseInt(value);
     let date = new Date(value);
     return date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate() + ' ' + date.getHours() + ':' + date.getMinutes() + ':' + date.getSeconds();*/
    let date = new Date(parseInt(value));

    let year = date.getFullYear(), month = date.getMonth() + 1,//月份是从0开始的
        day = date.getDate(), hour = date.getHours(), min = date.getMinutes(), sec = date.getSeconds();
    return year + '-' + (month < 10 ? '0' + month : month) + '-' + (day < 10 ? '0' + day : day) + ' ' + (hour < 10 ? '0' + hour : hour) + ':' + (min < 10 ? '0' + min : min) + ':' + (sec < 10 ? '0' + sec : sec);
}

function formatDate(value) {
    if (null == value || value === '' || value === undefined) return "";

    let date = new Date(parseInt(value));

    let year = date.getFullYear(), month = date.getMonth() + 1,//月份是从0开始的
        day = date.getDate();
    return year + '-' + (month < 10 ? '0' + month : month) + '-' + (day < 10 ? '0' + day : day);
}

function formatStr(str, count) {
    if (null === str || str === '' || str === undefined) return '';

    let result = str;

    if (str.length > count) result = str.substring(0, count) + '...';

    return '<span title="' + str + '">' + result + '</span>';
}

function formatPicUrl(picUrl) {
    if (null == picUrl || picUrl === '' || picUrl === undefined) {
        return '';
    } else {
        return '<img style="cursor: pointer;" onclick="window.open(\'' + picUrl + '\')" width="30px;" height="30px;" src="' + picUrl + '" alt="微信头像" title="点击查看大图" />';
    }
}

function getTime() {
    let date = new Date();

    let year = date.getFullYear(), month = date.getMonth() + 1,//月份是从0开始的
        day = date.getDate(), hour = date.getHours(), min = date.getMinutes(), sec = date.getSeconds();
    return year + '-' + (month < 10 ? '0' + month : month) + '-' + (day < 10 ? '0' + day : day) + ' ' + (hour < 10 ? '0' + hour : hour) + ':' + (min < 10 ? '0' + min : min) + ':' + (sec < 10 ? '0' + sec : sec);
}

let messageTime = 2000;

function info(msg, status) {
    cocoMessage.config({
        duration: messageTime
    });

    if (status === 'success') {
        cocoMessage.success(msg, messageTime);
    } else if (status === 'warning') {
        cocoMessage.warning(msg, messageTime);
    } else if (status === 'error') {
        cocoMessage.error(msg, messageTime);
    } else if (status === 'loading') {
        cocoMessage.loading(msg, messageTime);
    } else {
        cocoMessage.info(msg, messageTime);
    }
}